#!/usr/bin/perl -w
#run avrdude.pl -P/dev/ttyUSBN -Uflash:w:Release/whlogger.hex:i

use Device::SerialPort;
my $go;
foreach (@ARGV)
{
    if ($_ =~ /-P(\/dev\/.+USB.+)/)
    {
        print (STDERR "Resetting DTR on " . $1 . "\n");
        Device::SerialPort->new($1)->pulse_dtr_on(100);
	$go=1;
        last;
    }
}
unless($go){
  print (STDERR "Executing -P/dev/ttyUSBN -Uflash:w:Release/whlogger.hex:i\n");
  exit -1;
}
select(undef, undef, undef, 0.1);
print (STDERR "Executing avrdude\n");
#system("/usr/bin/avrdude " . join(" ", @ARGV)." -C../arduino-diecimila/avrdude.conf -pm168 -cstk500v1  -b19200 -D -F -q");
system("/usr/bin/avrdude " . join(" ", @ARGV)." -v -pm328p -carduino -b57600 -D -F -q");

